<?php

/**
 * @author Rizky Tahara Shita
 * @website http://tahara.web.id
 * @email rizky.tahara@gmail.com
 * @copyright b'IT Cyber Solution
 */

class M_live_data extends BZ_Model
{
/**
 * @section biskitZ Front-End Live Data Model
 */

	/**
	 * @function media_upload_file
	 * @description process the upload file
	 */
	public function media_upload_file($prm_css_result_file_name = '#txt74', $prm_css_result_file_type = '#txt75')
	{
		/**
		 * @description load biskitz front settings
		 */
		$this->web_data['BISKITZ_FRONT']['SETTINGS'] = $this->M_functions->setting_get('db_default', 'biskitz_front_settings');

		$upload_time = date('Ym');
		$upload_path = $this->web_data['BISKITZ_FRONT']['SETTINGS']['BISKITZ_FRONT_UPLOAD_DIR'].'/post/'.$upload_time;


		/**
		 * @description create the gallery folder if not exists
		 */
		if (is_dir($upload_path) == FALSE)
		{
			mkdir($upload_path, 0755);
		}
		$upload_path .= '/';

		/**
		 * @description upload configuration
		 */
		$upload_config = array
			(
				'upload_path' => $upload_path
				, 'allowed_types' => $this->web_data['BISKITZ_FRONT']['SETTINGS']['BISKITZ_FRONT_UPLOAD_TYPE_ALLOWED']
				, 'max_size' => $this->web_data['BISKITZ_FRONT']['SETTINGS']['BISKITZ_FRONT_UPLOAD_SIZE_MAX']
				, 'overwrite' => TRUE
			);
		$this->load->library('upload', $upload_config);
		$this->upload->initialize($upload_config);

		if ( ! $this->upload->do_upload('txtupload_file'))
		{
			$return_value = array
				(
					'js_upload_error'
					, array($this->upload->display_errors('', ''), 'error')
				);
		}
		else
		{
			$upload_result = $this->upload->data();

			$return_value = array
				(
					'js_upload_success'
					, array
						(
							$prm_css_result_file_name, $upload_result['file_name']
							, $prm_css_result_file_type, $upload_result['file_type']
						)
				);
		}


		$return_value = json_encode($return_value);
		echo $return_value;
	}


	/**
	 * @function category_combo_put
	 * @description get the data and put them in combobox
	 */
	public function category_combo_put($prm_tbl_attr = '', $prm_object_start = '0')
	{
		if (is_array($prm_tbl_attr))
		{
			/**
			 * @description load the models
			 */
			$this->load->model('M_viewlist');


			$return_value = array
				(
					'js_action_combo_item_add'
					, $this->M_viewlist->generate
						(
							'db_default'
							, $prm_tbl_attr['VIEW']['FIELDS'], $prm_tbl_attr['TABLE']['PRIMARY'], $prm_tbl_attr['VIEW']['FIELDS_EDIT'], $prm_tbl_attr['VIEW']['FIELDS_ORDER']
							, $prm_tbl_attr['TABLE']['NAME_ALIAS'], $prm_tbl_attr['VIEW']['TABLE']['WHERE']
							, ''
							, $this->bz_segment['END']
							, 0
							, array('form')
							, FALSE
							, FALSE
							, 'none'
							, 'FALSE'
							, FALSE, array()
							, TRUE
							, $prm_tbl_attr['VIEW']['FIELDS_PARENT_NAME']
							, TRUE
							, 0, 0
							, '&mdash;'
							, TRUE
						)
					, $prm_object_start
				);


			$return_value = json_encode($return_value);
			echo $return_value;
		}
	}



}

/** End of file M_live_data.php */
/** Location: ./biskitz_mpc/biskitz/models/admin/biskitz/front_end/m_live_data.php */